package com.huawei123.hasee.mynavigationview_view.Toolber_view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ScrollView;

/**
 * 项目名称：MyNavigationView_view
 * 类描述：自定义ScrollView,为了兼容低版本的滑动改变回调
 * 创建人：hasee
 * 创建时间：2017/5/29 22:47
 * 修改人：hasee
 * 修改时间：2017/6/1
 * 修改备注：工作电脑
 */
public class MyScrollView extends ScrollView {
    private MyScrollViewChangeListener myScrollViewChangeListener;

    public MyScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setTranslucentListener(MyScrollViewChangeListener myScrollViewChangeListener) {
        this.myScrollViewChangeListener = myScrollViewChangeListener;
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        if (myScrollViewChangeListener != null) {
            float transparent;
            float scaleY = getScrollY();//Scroll垂直方向坐标
            int heightPixels = getResources().getDisplayMetrics().heightPixels;//屏幕的垂直方向的高度

            if (scaleY <= heightPixels / 3f) {//0~1f,而透明度应该是1~0f
                transparent = 1 - (scaleY / (heightPixels / 3f));
                Log.d("luohao", transparent + "------transparent");
                myScrollViewChangeListener.scrollChange(transparent);
            }
        }
    }

    public interface MyScrollViewChangeListener {
        void scrollChange(float transparent);
    }
}
